﻿using Common.Infrastructure;
using System;
using System.Collections.Generic;
using System.Text;

namespace Common.EF
{
    public static class CommonEFUtils
    {
        public static void CheckCommonContext(IServiceProvider provider, ICommonContext context, string code)
        {
            if (context == null)
            {
                throw new NullReferenceException("comtext");
            }
        }

        public static void ThrowByIdError(IServiceProvider provider, string id)
        {
            throw new CommonException($"{id} format error");
        }

        public static void ThrowByNoDefaultContext(IServiceProvider provider)
        {
            throw new CommonException($"No default context");
        }

        public static void ThrowByNoContext(IServiceProvider provider)
        {
            throw new CommonException($"No exist context");
        }

        public static void ThrowByNoContextByEntity(IServiceProvider provider, string entityName)
        {
            throw new CommonException("no context by entity");
        }

        public static void ThrowBySpecialContextByEntity(IServiceProvider provider, string entityName)
        {
            throw new CommonException("no special context by entity");
        }

        public static void ThrowFieldUniqueError(IServiceProvider provider, string fieldName, params object[] objs)
        {
            throw new EntityFieldUniqueException(string.Empty, fieldName, "unique error");
        }
    }
}
